use trpl::Either;


fn main() {
    let args: Vec<String> = std::env::args().collect();

    trpl::run( async {
        // let t1 = page_title(&args[1]);
        // let t2 = page_title(&args[2]);

        // let maybe_title = match trpl::race(t1, t2).await {
        //     Either::Left(left) => left,
        //     Either::Right(right) => right,
        // };

        // match maybe_title {
        //     Some(title) => {
        //         println!("{}", title);
        //     },
        //     None => {
        //         println!("not title");
        //     }
        // };

        match page_title(&args[1]).await {
            Some(title) => {
                println!("{}", title);
            },
            None => {
                println!("not title");
            }
        }
    });
}

async fn page_title(url: &str) -> Option<String> {
    let response = trpl::get(url).await.text().await;
    trpl::Html::parse(&response)
        .select_first("title")
        .map(|title_element| title_element.inner_html())
}